package com.iotimc.attendancesystem.attendance.util;

import android.databinding.BindingAdapter;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.iotimc.attendancesystem.R;
import com.iotimc.attendancesystem.util.PictureManager;

/**
 * @author david
 */
public class ImageViewAttrAdapter {
  
    @BindingAdapter("android:src")
    public static void setSrc(ImageView view, Bitmap bitmap) {
        view.setImageBitmap(bitmap);  
    }  
  
    @BindingAdapter("android:src")
    public static void setSrc(ImageView view, int resId) {
        view.setImageResource(resId);  
    }

    @BindingAdapter("android:src")
    public static void setSrc(ImageView view, byte[] bytes) {
        if (bytes != null) {
            PictureManager.getInstance().loadCirclePic(view.getContext(),
                    bytes, view, false);
        } else {
            PictureManager.getInstance().loadCirclePic(view.getContext(),
                    R.drawable.error, view, false);
        }
    }
}  